from qiniu import Auth, put_file, etag
from qiniu.compat import is_py2, is_py3

# 需要填写你的 Access Key 和 Secret Key
access_key = 'f3jP9-aCVZWG2QgdxAwL_2qIXZaSdbjTUsfAa5Th'
secret_key = '99jjCCFpfjenCfswaeBm_7833P5vwxx8d7eej9OI'

# 构建鉴权对象
q = Auth(access_key, secret_key)

# 要上传的空间
# bucket_name = 'Pay-IM'

# 上传到七牛后保存的文件名
key = '2019/03/19/15ee9b24-4a5c-11e9-b0ce-88e9fe4e21cb'

# 生成上传 Token，可以指定过期时间等
token = 'f3jP9-aCVZWG2QgdxAwL_2qIXZaSdbjTUsfAa5Th:D0O0TLQ7Gz-O5z7SRpRmGQSpADA=:eyJzY29wZSI6InBheS1pbToyMDE5LzAzLzE5LzE1ZWU5YjI0LTRhNWMtMTFlOS1iMGNlLTg4ZTlmZTRlMjFjYiIsImRlYWRsaW5lIjozMTA2MDIyNTk0LCJmc2l6ZUxpbWl0IjoxMDQ4NTc2MCwibWltZUxpbWl0IjoiaW1hZ2UvKiJ9'

# 要上传文件的本地路径
localfile = '/Users/tiger/googlelogo_color_92x30dp.png'

ret, info = put_file(token, key, localfile)
print(ret)
print(info)

if is_py2:
    assert ret['key'].encode('utf-8') == key
elif is_py3:
    assert ret['key'] == key

assert ret['hash'] == etag(localfile)
